package org.abacus.platform.client.action;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class LoginDemo {
	/**
	 * Launch the application
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		final Display display = Display.getDefault();
		final Shell shell = new Shell();
		shell.setSize(500, 375);
		shell.setText("SWT Application");
		//

		shell.open();

		final Label usernameLabel = new Label(shell, SWT.NONE);
		usernameLabel.setText("用户名:");
		usernameLabel.setBounds(55, 54, 61, 35);

		final Text text = new Text(shell, SWT.BORDER);
		text.setBounds(163, 51, 93, 29);

		final Label passwordLabel = new Label(shell, SWT.NONE);
		passwordLabel.setText("密 码:");
		passwordLabel.setBounds(59, 113, 57, 29);

		final Text text_1 = new Text(shell, SWT.BORDER);
		text_1.setBounds(163, 98, 95, 29);

		final Button enterButton = new Button(shell, SWT.NONE);
		enterButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if (text.getText() != "" || text_1.getText() != "") {
					if ("admin".equals(text.getText()) && "admin".equals(text_1.getText())) {
						MessageDialog.openInformation(shell, "登陆信息", "欢迎" + text.getText() + "登陆系统");
					} else {
						MessageDialog.openInformation(shell, "登陆失败", "请输入正确的用户名密码！");
					}
				} else {
					MessageDialog.openError(shell, "登陆失败", "请至少输入用户名吧");
				}
			}
		});
		enterButton.setText("确定");
		enterButton.setBounds(78, 175, 107, 35);

		final Button resetButton = new Button(shell, SWT.NONE);
		resetButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				text.setText("");
				text_1.setText("");
			}
		});
		resetButton.setText("重置");
		resetButton.setBounds(225, 175, 118, 35);
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}
}
